// /pages/team-list/team-list.js
import { getDeleteworkerListIds, deleteProjectBatchStaff } from "../../api/pay"
import user from "../../../utils/user"
import { confirm } from "../../../utils/util"
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        idS:[],
        list:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log(options, 'options')
        user.waitLogin().then(() => {
            this.getDeleteworkerListIds()
        })
        this.setData({
            idS:options.ids.split(',')
        })
        console.log(this.data.idS, 'idS')
    },
    onShow() {
       
    },
    async getDeleteworkerListIds () {
        console.log(String(this.data.idS))
        const result = await getDeleteworkerListIds(String(this.data.idS))
        result.forEach((item,index) => {
            result[index].encryptionCard = item.idCardNo.substr(14)
        })
        console.log(result, 'result')
        this.setData({
            list:result
        })
    },
    onDelete(){
        console.log('确定删除')
        if(this.data.list.length === 0){
            app.toast('至少存在一位员工')
            return
        }
        confirm('确认删除吗').then(async () => {
            await deleteProjectBatchStaff(this.data.idS)
            await this.getDeleteworkerListIds()
            app.toast('删除成功')
            const eventChannel = this.getOpenerEventChannel()
            eventChannel.emit('acceptDataFromOpenedPage', {data: true});
            setTimeout(()=>{
                wx.navigateBack()
            },500)
        })
    },
})